package com.taoyibao.hongcanting.dialog;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.cache.SpUtils;
import com.taoyibao.hongcanting.model.MapDishModel;
import com.taoyibao.hongcanting.model.UserTableModel;
import com.taoyibao.hongcanting.ui.home.activity.MenuActivity;
import com.taoyibao.hongcanting.ui.home.activity.PayActivity;
import com.taoyibao.hongcanting.ui.mine.activity.WaitPayActivity;
import com.taoyibao.hongcanting.ui.restaurant.area.MainBottomArea;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.widget.BottomBarItem;

/**
 * @author TangAnna
 * @description: 地图中的操作点餐
 * @date :${DATA} 11:36
 */
@SuppressLint("ValidFragment")
public class DialogMapTable extends BaseFragmentDialog implements View.OnClickListener, MainBottomArea.BottomSelectedListener {
    /**
     * 桌号
     */
    private TextView mTvTableNub;
    /**
     * 人数
     */
    private TextView mTvNub;
    /**
     * 右上角的文字
     */
    private TextView mTvTitle;
    /**
     * 风格
     */
    private TextView mTvStyle;
    /**
     * 已点菜品
     */
    private TextView mTvYiDianDish;
    /**
     * 加菜
     */
    private TextView mTvAddDish;
    /**
     * 结账
     */
    private TextView mTvPay;
    /**
     * 点菜
     */
    private TextView mTvDianCai;
    /**
     * 赠送
     */
    private TextView mTvZengSong;
    /**
     * 帮结账
     */
    private TextView mTvhelpPay;
    /**
     * 页面显示标记值 1显示一个按钮 2显示两个按钮 3显示三个按钮
     */
    private int mType;
    private MainBottomArea mMainBottomArea;

    /**
     * 数据
     */
    private MapDishModel mMapDishModel;
    //当前桌位的信息
    private UserTableModel mTableInfo;

    public DialogMapTable(MapDishModel mapDishModel) {
        mMapDishModel = mapDishModel;
    }

    @Override
    protected void setData() {
        super.setData();
        if (mMapDishModel != null && mMapDishModel.mTableInfo != null) {
            mTableInfo = mMapDishModel.mTableInfo;
            if (!TextUtils.isEmpty(mTableInfo.desk_name)) {
                mTvTableNub.setText(mTableInfo.desk_name);
            }
            //是否已就坐
            if (mMapDishModel.isDown && TextUtils.equals(mMapDishModel.tableStatus, "1")) {
                mTvTitle.setText("我的餐桌");
                mTvTitle.setTextColor(CodeUtils.getIdColor(R.color.color333));
            }
            if (!mMapDishModel.isDown) {
                mTvTitle.setText("您尚未就坐");
                mTvTitle.setTextColor(CodeUtils.getIdColor(R.color.colorf46));
            }
        }
    }

    @Override
    protected void setListener(View view) {
        super.setListener(view);
        mTvAddDish.setOnClickListener(this);
        mTvPay.setOnClickListener(this);
        mTvDianCai.setOnClickListener(this);
        mTvZengSong.setOnClickListener(this);
        mTvhelpPay.setOnClickListener(this);
        mTvYiDianDish.setOnClickListener(this);
    }

    @Override
    protected int setAnimation() {
        return 0;
    }

    @Override
    protected int setGravity() {
        return Gravity.BOTTOM;
    }

    @Override
    public int bindView() {
        return R.layout.dialog_map_dish;
    }

    @Override
    protected void initView(View view) {
        super.initView(view);
        mTvTableNub = view.findViewById(R.id.tv_dialogMapDish_tableNub);
        mTvNub = view.findViewById(R.id.tv_dialogMapDish_nub);
        mTvTitle = view.findViewById(R.id.tv_dialogMapDish_title);
        mTvStyle = view.findViewById(R.id.tv_dialogMapDish_style);
        mTvYiDianDish = view.findViewById(R.id.tv_dialogMapDish_yiDianDish);
        mTvAddDish = view.findViewById(R.id.tv_dialogMapDish_addDish);
        mTvPay = view.findViewById(R.id.tv_dialogMapDish_pay);
        mTvDianCai = view.findViewById(R.id.tv_dialogMapDish_dianCan);
        mTvZengSong = view.findViewById(R.id.tv_dialogMapDish_zengSong);
        mTvhelpPay = view.findViewById(R.id.tv_dialogMapDish_helpPay);
        mMainBottomArea = view.findViewById(R.id.layout_bottom);
        mMainBottomArea.setBottomSelectedListener(this);
        if (TextUtils.equals(mMapDishModel.tableStatus, "0")) {
            view.findViewById(R.id.layout_dialogMapDish_two).setVisibility(View.GONE);
            view.findViewById(R.id.layout_dialogMapDish_three).setVisibility(View.GONE);
            view.findViewById(R.id.tv_dialogMapDish_dianCan).setVisibility(View.VISIBLE);
        } else if (TextUtils.equals(mMapDishModel.tableStatus, "2")) {
            view.findViewById(R.id.layout_dialogMapDish_two).setVisibility(View.VISIBLE);
            view.findViewById(R.id.layout_dialogMapDish_three).setVisibility(View.GONE);
            view.findViewById(R.id.tv_dialogMapDish_dianCan).setVisibility(View.GONE);
        } else if (TextUtils.equals(mMapDishModel.tableStatus, "1")) {
            mTvTitle.setTextColor(CodeUtils.getIdColor(R.color.color333));
            view.findViewById(R.id.layout_dialogMapDish_two).setVisibility(View.GONE);
            view.findViewById(R.id.layout_dialogMapDish_three).setVisibility(View.VISIBLE);
            view.findViewById(R.id.tv_dialogMapDish_dianCan).setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_dialogMapDish_addDish://加菜
                SpUtils.putOtherSeatName("");
                SpUtils.putOtherSeatId("");
                MenuActivity.open(getContext());
                break;
            case R.id.tv_dialogMapDish_pay://结账
                SpUtils.putOtherSeatName("");
                SpUtils.putOtherSeatId("");
                if (mTableInfo != null) {
                    PayActivity.open(getContext(), mTableInfo.order_id, SpUtils.getMemberId(), mTableInfo.desk_code);
                }
                break;
            case R.id.tv_dialogMapDish_dianCan://点餐
                SpUtils.putOtherSeatName("");
                SpUtils.putOtherSeatId("");
                if (mMapDishModel != null && mTableInfo != null) {
                    if (!TextUtils.isEmpty(mMapDishModel.mTableInfo.desk_code)) {
                        SpUtils.putSeatId(mMapDishModel.mTableInfo.desk_code);
                        SpUtils.putSeatName(mMapDishModel.mTableInfo.desk_name);
                    }
                    MenuActivity.open(getContext());
                }
                break;
            case R.id.tv_dialogMapDish_zengSong://赠送
                if (mTableInfo != null) {
                    //临时存放的值  将要赠送的座位信息

                    SpUtils.putOtherSeatName(mTableInfo.desk_name);
                    SpUtils.putOtherSeatId(mTableInfo.desk_code);
                    MenuActivity.open(getContext());
                }
                break;
            case R.id.tv_dialogMapDish_helpPay://帮结账
                SpUtils.putOtherSeatName("");
                SpUtils.putOtherSeatId("");
                if (mTableInfo != null) {
                    PayActivity.open(getContext(), mTableInfo.order_id, mTableInfo.order_member_id, mTableInfo.desk_code);
                }
                break;
            case R.id.tv_dialogMapDish_yiDianDish://已点菜品
                SpUtils.putOtherSeatName("");
                SpUtils.putOtherSeatId("");
                if (mTableInfo != null) {
                    WaitPayActivity.open(getContext(), mTableInfo.order_id, mTableInfo.desk_code);
                }
                break;
        }
        dismiss();
    }

    @Override
    public void Selected(BottomBarItem bottomBarItem, int position) {
        dismiss();
    }
}
